﻿/*
 * Created by SharpDevelop.
 * User: cszhangyi
 * Date: 2016/9/8
 * Time: 14:18
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace JsonTest
{
	class Program
	{ 
		public static void Main(string[] args)
		{
			Console.WriteLine("Hello World!");
			
			// TODO: Implement Functionality Here
			string json="[{\"name\":\"zhangsan\",\"age\":12, \"sex\":\"male\"},{\"name\":\"lisi\",\"age\":13}]";
			JArray arr = (JArray)JsonConvert.DeserializeObject(json);
		
			List<Student> students = JsonConvert.DeserializeObject<List<Student>>(json);
			
			foreach (JObject obj in arr)
			{
				if (obj["sex"] == null)
					obj["sex"] = "a";
				
				Console.WriteLine(obj["sex"].ToString());
			}
			
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
	}
}